
class Link {
  constructor ({ gantt, vue, VueGantt }) {
    this.gantt = gantt
    this.vue = vue
    this.VueGantt = VueGantt
  }

  registerEvent () {
    this.gantt.attachEvent('onAfterLinkDelete', (id, item) => {
      this.setLineData('onAfterLinkDelete')
    })
    this.gantt.attachEvent('onAfterLinkAdd', (id, item) => {
      this.setLineData('onAfterLinkAdd')
    })
    this.gantt.attachEvent('onAfterLinkUpdate', (id, item) => {
      this.setLineData('onAfterLinkUpdate')
    })
  }

  setLineData (ev) {
    const { task } = this.VueGantt
    task.links = this.VueGantt.getLinks()
    this.vue.$emit('input', task)
    this.vue.$emit(ev, task.links)
  }

  init () {
    this.registerEvent()
  }
}

export default Link
